﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using Server;
using Server.Services.DTO;

namespace Server.Services
{

    class WebServices : IWebServices
    {
        private Controller _controller;

        public WebServices(Controller controler)
        {
            _controller = controler;

        }

        public Guid RegisterComputingUnit(string processorName, short logicalProcessor)
        {
            OperationContext context = OperationContext.Current;
            MessageProperties prop = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpoint =
                prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
            string ip = endpoint.Address;
            return _controller.RegisterComputingUnit(new Processor { Name = processorName, LogicalProcess = logicalProcessor }, ip);
        }

        public bool Hello(Guid unitId)
        {
            return _controller.IsExistUnit(unitId);
        }

        public LibInterface.Compiuting GetNextCompiutingData(Guid unitId)
        {
            return this._controller.GetNextCompiutingData(unitId);

        }
        public List<ProjectDTOBasic> GetActiveProjects(Guid id)
        {
            return _controller.GetActiveProjects();
        }


        public byte[] GetParamiter(Guid unitId, int projectId, int paramiterId, bool isDynamic)
        {
            return this._controller.GetParamiter(projectId, paramiterId, isDynamic);
        }

        public ProjectDTOBasic GetListQueueProject(Guid unitId)
        {
            return new ProjectDTOBasic();
        }

        public List<ProjectFilesDTO> GetProjectFiles(Guid unitId, int projectId){
            return _controller.GetProjectFiles(projectId);
        }


    }
}
